import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

Vue.config.productionTip = false;

//导入axios对象，配置Vue原型
import axios from "./utils/request";
Vue.prototype.$axios = axios;

import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
Vue.use(ElementUI);

//配置echarts
import * as echarts from "echarts";
Vue.prototype.$echarts = echarts;

// 挂载路由守卫
router.beforeEach((to, from, next) => {
  if (to.path == "/login") {
    if (store.state.token != "") {
      next("/index");
    }
  } else {
    if (store.state.token == "") {
      next("/login");
    }
  }
  next();
});

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
